<template>
  <div>
    <!-- 标签栏滚动 -->
    <van-tabs v-model="active" @click="todi">
      <van-tab
        :title="item.name"
        v-for="item in brotherCategory"
        :key="item.id"
      >
        <h3 class="hname">{{ item.name }}</h3>
        <p class="pname">{{ item.front_name }}</p>
      </van-tab>
    </van-tabs>
    <!-- 下面图片 -->
    <ul>
      <li v-for="item in goodsList" :key="item.id">
        <img
          :src="item.list_pic_url"
          style="display: block"
          width="100%"
          alt=""
        />
        <div class="van-ellipsis">{{ item.name }}</div>
        <div class="price">{{ item.retail_price }}</div>
      </li>
    </ul>
  </div>
</template>

<script>
import Products from "@/components/Products.vue";
import { GetCateGoryData, GetCateGoryList } from "@/utils/http";
export default {
  name: "Channel",
  data() {
    return {
      active: 0,
      brotherCategory: [], // 9个所有数据
      goodsList: [], //商品数据
      categoryId: "",
    };
  },
  components: {
    Products,
  },
  created() {
    //获取所有分类数据
    GetCateGoryData({
      id: this.$route.query.id,
    }).then((res) => {
      // console.log("aaa", res);
      //产品数组
      this.brotherCategory = res.data.data.brotherCategory;
      //分类id
      this.categoryId = res.data.data.currentCategory.id.toString();
      this.brotherCategory.forEach((item,index)=>{
        if(this.$route.query.id==item.id){
          this.active=index; 
        }
      })
      this.dianji(this.categoryId)
    });
  },
  methods: {
    todi(title, name) {  //点击事件回调
      console.log(title, name);
      this.brotherCategory.forEach((item) => {
        if (item.name == name) {
          this.categoryId = item.id.toString();
        }
      });
      //再次调用列表请求
      this.dianji(this.categoryId);
    },
    dianji(id) {
      let params={
        categoryId:id, //当前分类id
        page:this.page, //当前页数
        size:this.size, //每页显示个数
      }
      //发送商品列表请求
    GetCateGoryList(params).then((res) => {
        // console.log(res);
        //获取商品列表信息
        this.goodsList = res.data.data.goodsList;
      });
    },
    
  },
};
</script>

<style lang='less' scoped>
.hname {
  text-align: center;
  font-size: 9px;
  margin-top: 10px;
}
.pname {
  text-align: center;
  font-size: 6px;
  margin-top: 10px;
  margin-bottom: 10px;
}
ul {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  li {
    width: 49%;
    margin-bottom: 0.1rem;
    text-align: center;
    line-height: 0.5rem;
    .van-ellipsis {
      font-size: 7px;
      margin-top: 8px;
      margin-bottom: 5px;
    }
    .price {
      font-size: 7px;
    }
  }
}
</style>